package com.xjtu.se.homework.ops.login.controller;

import com.xjtu.se.homework.common.Result;
//import com.xjtu.se.homework.common.TokenUtils;
import com.xjtu.se.homework.common.TokenUtils;
import com.xjtu.se.homework.ops.login.dto.AdminDto;
import com.xjtu.se.homework.ops.login.service.LoginService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/ops/login")
public class LoginAPI {

    @Resource
    private LoginService loginService;

    @PostMapping("")
    public Result checkadmin(@RequestBody AdminDto dto) {

        boolean ok = loginService.checkadmin(dto);

        if (ok) {
//            生成一个登录令牌
            String token = TokenUtils.loginSign(dto.getAdminId(), dto.getAdminPass());
            return Result.success((Object) token);//向客户端发送成功信号
        }
        return Result.fail(Result.ERR_CODE_BUSINESS, "帐号或密码错误");
    }
}
